#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->switchBtn->setIcon(QIcon(":/icons/24gf-volumeCross.png"));
    ui->switchBtn->setIconSize(QSize(40, 40));
    ui->switchBtn->resize(40, 40);
}

void Widget::setButtonIcon()
{
    if (this->volume == 0)
    {
        ui->switchBtn->setIcon(QIcon(":/icons/24gf-volumeCross.png"));
    }
    else if (this->volume <= 33)
    {
        ui->switchBtn->setIcon(QIcon(":/icons/24gf-volumeLow.png"));
    }
    else if (this->volume <= 66)
    {
        ui->switchBtn->setIcon(QIcon(":/icons/24gf-volumeMiddle.png"));
    }
    else
    {
        ui->switchBtn->setIcon(QIcon(":/icons/24gf-volumeHigh.png"));
    }
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_adjustSlider_valueChanged(int value)
{
    this->volume = value;
    this->setButtonIcon();
    ui->digitLabel->setNum(value);
}

void Widget::on_switchBtn_clicked()
{
    if (isMuted)
    {
        ui->adjustSlider->setValue(prevVolume);
        this->setButtonIcon();
        isMuted = false;
    }
    else
    {
        prevVolume = ui->digitLabel->text().toInt();
        ui->adjustSlider->setValue(0);
        isMuted = true;
    }
}
